# -*- coding: utf-8 -*-
"""
UTc! module: profiler

Purpose
=======
 An entry-point to the sandbox that profiles the performace of UTc!'s core API.
 
 This script is basically just a hack used to gather performance data.
 
Usage
=====
 Run 'python profiler' once to generate a stats file, then run
 'python profiler x > log.log' to print the stats to a readable logfile,
 log.log.
 
Legal
=====
 All code, unless otherwise indicated, is original, and subject to the
 terms of the GPLv2, which is provided in COPYING.
 
 (C) Neil Tallim, 2009
"""
import sys

if __name__ == '__main__':
	if len(sys.argv) == 1:
		import cProfile
		import sandbox
		
		class Blank(object):
			pass
			
		ship_path = "assets/objects/ships/tc00.xml"
		
		options = Blank()
		options.wireframe = options.gradient = options.flat = False
		options.plain = True
		options.fsaa = 0
		options.rnd_hud = True
		options.debug_solid = False
		options.hitboxes = False
		options.weapons = False
		
		cProfile.run('sandbox._run(ship_path, options)', 'profile.log')
	else:
		import pstats
		
		stats = pstats.Stats('profile.log')
		stats = stats.sort_stats('time')
		stats.print_stats()
		